home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / NeoIntroPP3.0 folder / PowerPlant / NeoBench / Source / CNeoBenchDoc.cp < prev    next >
Encoding:
Text File  |  1994-08-06  |  3.4 KB  |  144 lines  |  [TEXT/MMCC]

  1. /****
  2.  * CNeoBenchDoc.cp
  3.  *
  4.  *    Document methods for a typical application.
  5.  *
  6.  *  Copyright © 1990 Symantec Corporation.  All rights reserved.
  7.  *
  8.  ****/
  9.  
  10. #include "NeoTypes.h"
  11. #include "PP_Messages.h"
  12. #include "UDesktop.h"
  13. #include CNeoDatabaseNativeH
  14. #include "NeoBench.h"
  15. #include "CNeoBenchApp.h"
  16. #include "CNeoBenchDoc.h"
  17. #include "CNeoWindow.h"
  18.  
  19. #define    WINDNeoBench        500            /* Resource ID for WIND template */
  20.  
  21. /***
  22.  * CNeoBenchDoc
  23.  *
  24.  *    This is your document's initialization method.
  25.  *    If your document has its own instance variables, initialize
  26.  *    them here.
  27.  *
  28.  *    The least you need to do is invoke the default method.
  29.  *
  30.  ***/
  31. CNeoBenchDoc::CNeoBenchDoc(const Boolean aPrintable, const Boolean aNewDatabase, const Boolean aRemote)
  32.     : CNeoDocRoot(kNeoBenchSig, kNeoBenchFileType, aPrintable, aNewDatabase)
  33. {
  34. }
  35.  
  36. /***
  37.  * buildWindow
  38.  *
  39.  *    This is the auxiliary window-building method that the
  40.  *    newFile() and openFile() methods use to create a window.
  41.  *
  42.  *    In this implementation, the argument is the data to display.
  43.  *
  44.  ***/
  45.  
  46. void CNeoBenchDoc::buildWindow(void)
  47. {
  48.     /**
  49.      **    Create the window and initialize it.
  50.      **/
  51.     mWindow = new CNeoWindow(WINDNeoBench, this);
  52. }
  53.  
  54. void CNeoBenchDoc::ListenToMessage(MessageT aMessage, void *aParam)
  55. {
  56.     short                phase;
  57.     CNeoDatabasePP *    file;
  58.  
  59.     switch (aMessage) {
  60.     case msg_GrowZone:
  61.         file = (CNeoDatabasePP *)mFile;
  62.         if (file &&
  63.             file->isOpen() &&
  64.             *(NeoSize *)aParam) {
  65.     
  66.             if (isDirty()) {
  67.                 file->commit(FALSE);
  68.                 setDirty(FALSE);
  69.             }
  70.     
  71.             phase = ((CNeoWindow *)mWindow)->getPhase();
  72.             if (phase == kRandomly) {
  73.                 CNeoDatabase::FPurgeLevel = CNeoPersist::FPurgeDesperation +1;
  74.                 CNeoDatabase::FPurgeMin = ((CNeoWindow *)mWindow)->getPhaseTarget(kInsert) / 16;
  75.                 CNeoDatabase::FPurgeDelta = CNeoDatabase::FPurgeMin / 2;
  76.             }
  77.             else {
  78.                 if (phase == kInsert)
  79.                     CNeoDatabase::FPurgeMin = 2000;
  80.                 else
  81.                     CNeoDatabase::FPurgeMin = 200;
  82.                 CNeoDatabase::FPurgeDelta = CNeoDatabase::FPurgeMin / 4;
  83.                 CNeoDatabase::FPurgeLevel = CNeoPersist::FPurgeDesperation +3;
  84.             }
  85.             if (!file->purge(*(NeoSize *)aParam))
  86.                 *(NeoSize *)aParam = 0;
  87.         }
  88.         break;
  89.  
  90.     default:
  91.         inherited::ListenToMessage(aMessage, aParam);
  92.         break;
  93.     }
  94. }
  95.  
  96. /***
  97.  * newFile
  98.  *
  99.  *    When the user chooses New from the File menu, the CreateDocument()
  100.  *    method in your Application class will send a newly created document
  101.  *    this message. This method needs to create a new window, ready to
  102.  *    work on a new document.
  103.  *
  104.  *    Since this method and the openFile() method share the code for creating
  105.  *    the window, you should use an auxiliary window-building method.
  106.  *
  107.  ***/
  108. void CNeoBenchDoc::newDatabase(void)
  109. {
  110.     FSSpec    spec;
  111.  
  112.     inherited::newDatabase();
  113.  
  114.     ((CNeoWindow *)mWindow)->setDocument(this);
  115.  
  116.     spec.vRefNum = 0;
  117.     spec.parID = 0;
  118.     BlockMove("\pNeoBench Results", spec.name, 18);
  119.     ((CNeoDatabasePP *)mFile)->setFileSpec(spec);
  120.     DoSave();
  121.     setDirty(FALSE);
  122. }
  123.  
  124. /***
  125.  * openFile
  126.  *
  127.  *    When the user chooses Open… from the File menu, the OpenDocument()
  128.  *    method in your Application class will let the user choose a file
  129.  *    and then send a newly created document this message. The information
  130.  *    about the file is in the SFReply record.
  131.  *
  132.  *    In this method, you need to open the file and display its contents
  133.  *    in a window. This method uses the auxiliary window-building method.
  134.  *
  135.  ***/
  136.  
  137. void CNeoBenchDoc::openFile(FSSpec *aSpec)
  138. {
  139.     fOpenMode = fsRdWrPerm;
  140.     inherited::openFile(aSpec);
  141.  
  142.     ((CNeoWindow *)mWindow)->setDocument(this);
  143. }
  144.